home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
xmmlrg.exe
/
XMMTEST.C
< prev
Wrap
C/C++ Source or Header
|
1991-09-05
|
9KB
|
284 lines
/*************************************************************************
* *
* Test Program for the XMMHLDLR package *
* *
*************************************************************************/
#ifndef LINT_ARGS
#define LINT_ARGS
#endif
#ifndef ANSI
#define ANSI
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "prebelif.h"
#include "xmmhndlr.h"
/*************************************************************************
* *
* Local Defines *
* *
*************************************************************************/
#define S_OKAY 0
#define S_NOTFOUND 2
#define TRUE 1
#define FALSE 0
#define NUM_HANDLES 12
#define MAX_RECS 2000
#define RECSIZE 128
#define RECSIZE_INT (RECSIZE/2)
/*************************************************************************
* *
* Fucntion Prototypes *
* *
*************************************************************************/
int main(void);
void Fill(int *ptr,int pattern,int count);
int Cmp(int *ptr1,int *ptr2,int count);
void PutRecs(XHandle hnd, int type);
void GetCmpRecs(XHandle hnd);
void GetExistRecs(XHandle hnd);
/*************************************************************************
* *
* Main line *
* *
*************************************************************************/
int main()
{
int i;
XHandle hnd_tab[NUM_HANDLES];
int status;
if (InitXMMSystem(NUM_HANDLES) != S_OKAY) /* do an init */
{
printf("InitXMMSystem failed\n");
return(1);
}
printf("Init was successful\n");
/*************************************************************************
* *
* Alocate Tables *
* *
*************************************************************************/
for (i=0; i < NUM_HANDLES; i++)
{
hnd_tab[i] = AllocateXMMArea((long)MAX_RECS, RECSIZE);
if (hnd_tab[i] < 0) /* fail?? */
{
printf("Allocate area %d failed - ret=%d code=%x\n",
i, hnd_tab[i], XMMErrorCode);
return(1);
}
}
printf("Allocation of %d XMM Areas was successful\n", NUM_HANDLES);
/*************************************************************************
* *
* Test Put / Record exists check with null records *
* *
*************************************************************************/
for (i=0; i < NUM_HANDLES; i++)
{
PutRecs(hnd_tab[i], FALSE);
}
printf("Record Puts (NULL) on %d XMM Areas completed\n", NUM_HANDLES);
for (i=0; i < NUM_HANDLES; i++)
{
GetExistRecs(hnd_tab[i]);
}
printf("Record Exists from %d XMM Areas completed\n", NUM_HANDLES);
/*************************************************************************
* *
* Test Put / Get Record *
* *
*************************************************************************/
for (i=0; i < NUM_HANDLES; i++)
{
PutRecs(hnd_tab[i], TRUE);
}
printf("Record Puts on %d XMM Areas completed\n", NUM_HANDLES);
for (i=0; i < NUM_HANDLES; i++)
{
GetCmpRecs(hnd_tab[i]);
}
printf("Record Gets from %d XMM Areas completed\n", NUM_HANDLES);
/*************************************************************************
* *
* Deallocate Tables *
* *
*************************************************************************/
for (i=0; i < NUM_HANDLES; i++)
{
status = DeAllocateXMMArea(hnd_tab[i]);
if (status != S_OKAY) /* fail?? */
{
printf("DeAllocate area %d failed - ret=%d code=%x\n",
i, status, XMMErrorCode);
return(1);
}
}
printf("Deallocation of %d XMM Areas was successful\n", NUM_HANDLES);
/*************************************************************************
* *
* Shut Down *
* *
*************************************************************************/
if (ShutXMMSystem() != S_OKAY)
{
printf("ShutXMMSystem failed\n");
return(1);
}
printf("Shut was successful\n");
return(0);
}
/*<f>*/
void PutRecs(XHandle hnd, int type)
/*************************************************************************
* *
* Fill each record of this XMM area with a record based on recno *
* *
*************************************************************************/
{
int record[RECSIZE_INT];
int i;
int status;
for (i=0; i < MAX_RECS; i++)
{
if (type == TRUE)
Fill(record, i, RECSIZE_INT);
else
memset((char *)record, '\0', sizeof(record));
status = PutXMMRecord(hnd, (long)i, record);
if (status != S_OKAY)
{
printf("Put in area %d failed for record %d- ret=%d code=%x\n",
hnd, i, status, XMMErrorCode);
return;
}
}
}
void GetCmpRecs(XHandle hnd)
/*************************************************************************
* *
* Get each record of this XMM area and compare with what we put *
* *
*************************************************************************/
{
int record[RECSIZE_INT];
int cmp_rec[RECSIZE_INT];
int i;
int status;
for (i=0; i < MAX_RECS; i++)
{
Fill(cmp_rec, i, RECSIZE_INT); /* fill what we put */
status = GetXMMRecord(hnd, (long)i, record);
if (status != S_OKAY)
{
printf("Get in area %d failed for record %d- ret=%d code=%x\n",
hnd, i, status, XMMErrorCode);
return;
}
if (Cmp(record, cmp_rec, RECSIZE_INT)) /* compare what we got */
{
printf("Compare Failed in area %d failed for record %d\n", hnd, i);
return;
}
}
}
void GetExistRecs(XHandle hnd)
/*************************************************************************
* *
* See if each record in this XMM area exists - it should not *
* *
*************************************************************************/
{
int record[RECSIZE_INT];
int cmp_rec[RECSIZE_INT];
int i;
int status;
for (i=0; i < MAX_RECS; i++)
{
status = CheckXMMRecord(hnd, (long)i);
if (status != S_NOTFOUND)
{
printf("Check in area %d failed for record %d- ret=%d code=%x\n",
hnd, i, status, XMMErrorCode);
return;
}
}
}
/*<f>*/
void Fill(int *ptr,int pattern,int count)
/*************************************************************************
* *
* Fill a word area with a pattern based on a